#include <Window.hpp>
#include <Common.hpp>

namespace NaturalEngine {

    Window::Window(const i32 width, const i32 height, const i32 flags) {
        if (SDL_Init(SDL_INIT_EVERYTHING))
            throw std::runtime_error("Failed to initialize SDL");
        _handler = SDL_CreateWindow("自然引擎",
                                    SDL_WINDOWPOS_CENTERED,
                                    SDL_WINDOWPOS_CENTERED,
                                    width, height,
                                    flags | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
    }

    bool Window::Update() {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                return false;
            }
        }
        return true;
    }

    Window::~Window() {
        SDL_DestroyWindow(_handler);
        SDL_Quit();
    }
}
